package com.llkj.qingnianguoxue.adapter;

import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.HotRankingBean;
import com.llkj.qingnianguoxue.util.ClickViewCallback;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 图书详情——相关推荐
 */
public class BookRecommendAdapter extends BaseQuickAdapter<HotRankingBean.RankingBean, BaseViewHolder> {
    private int mType = 1;
    private ClickViewCallback listener;

    public BookRecommendAdapter(int layoutResId, List<HotRankingBean.RankingBean> data) {
        super(layoutResId, data);
        this.listener = listener;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, HotRankingBean.RankingBean item) {
        ImageView ivPic = baseViewHolder.getView(R.id.pic);
        ImageLoadingUtil.loadingUrl(ivPic, item.getImg());
        baseViewHolder.setText(R.id.tv_title, item.getTitle());//
        baseViewHolder.setText(R.id.tv_introduction, item.getAbstractX());
        baseViewHolder.setText(R.id.tv_price,"￥"+ item.getPrice());

        FrameLayout.LayoutParams picParam = (FrameLayout.LayoutParams) ivPic.getLayoutParams();
        picParam.width = DisplayUtil.getDensityWdith(mContext)*150/750;
        picParam.height = picParam.width*200/150;

        ImageView ivPlay = baseViewHolder.getView(R.id.iv_video_play);
        ivPlay.setVisibility(View.INVISIBLE);
        TextView tvBuy = baseViewHolder.getView(R.id.tv_buy);
        ImageView ivShopCart = baseViewHolder.getView(R.id.iv_add_shop);
        tvBuy.setVisibility(View.INVISIBLE);
        ivShopCart.setVisibility(View.INVISIBLE);
    }
    public void setListener(final int position,final View v){
        v.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(listener !=null){
                    listener.clickViewCallback(position,0,v);
                }
            }
        });
    }
    /**
     * 设置视频图书
     * @param type
     * 1视频，2图书，默认视频
     */
    public void setType(int type){
        mType = type;
    }
}
